//
//  LSZNicknameVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/9/30.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZNicknameVC.h"

@interface LSZNicknameVC ()<UITextViewDelegate>
@property(nonatomic,strong)UITextView * textView;
@end

@implementation LSZNicknameVC

- (void)viewDidLoad {
    [super viewDidLoad];
    InsetsTextField * textField = [[InsetsTextField alloc]init];
    [self.view addSubview:textField];

    self.textView = [[UITextView alloc]init];
    [self.view addSubview:self.textView];
    int A;
    if ([self.whereFrom isEqualToString:@"1"]) {
        self.title = @"修改昵称";
        textField.tag = 1;
        [textField.layer setMasksToBounds:YES];
        textField.placeholder = @"请填写您要修改的昵称!";
        [textField.layer setCornerRadius:5];
        textField.clearButtonMode = UITextFieldViewModeAlways;
        textField.backgroundColor = [UIColor whiteColor];
        A = 0;
    }else if ([self.whereFrom isEqualToString:@"0"]){
        self.title = @"个人简历";
        self.textView.delegate = self;
        self.textView.font = FONT_(15);
        self.textView.textAlignment = NSTextAlignmentLeft;
        self.textView.text = @"请填写你要修改的个人简介!";
        self.textView.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
        A = 2;
    }
    else{
        self.title = @"个人介绍";
        self.textView.delegate = self;
        self.textView.font = FONT_(15);
        self.textView.textAlignment = NSTextAlignmentLeft;
        self.textView.text = @"请填写你要修改的个人介绍!";
        self.textView.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
        A = 1;
    }
    UIButton * butOk = [[UIButton alloc]init];
    butOk.backgroundColor = redUIColor;
    [butOk.layer setMasksToBounds:YES];
    [butOk.layer setCornerRadius:5];
    [butOk setTitle:@"确定" forState:UIControlStateNormal];
    [butOk addTarget:self action:@selector(clickButOk) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:butOk];

    if (ScreenWidth == 320) {
        textField.font = FONT_(13.5);
        butOk.titleLabel.font = FONT_(13.5);
        if (A == 0) {
            textField.frame = CGRectMake(10, 20+NAVIGATION_BAR_HEIGHT, ScreenWidth-20, 45);
            butOk.frame = CGRectMake(10, CGRectGetMaxY(textField.frame)+100, ScreenWidth-20, 45);
        }else{
            self.textView.frame = CGRectMake(10, 20+NAVIGATION_BAR_HEIGHT, ScreenWidth-20, 90);
            butOk.frame = CGRectMake(10, CGRectGetMaxY(self.textView.frame)+100, ScreenWidth-20, 45);
        }
    }else if(ScreenWidth == 375){
        textField.font = FONT_(14);
        butOk.titleLabel.font = FONT_(14);
        if (A == 0) {
            textField.frame = CGRectMake(10, 20+NAVIGATION_BAR_HEIGHT, ScreenWidth-20, 50);
            butOk.frame = CGRectMake(10, CGRectGetMaxY(textField.frame)+100, ScreenWidth-20, 50);
        }else{
            self.textView.frame = CGRectMake(10, 20+NAVIGATION_BAR_HEIGHT, ScreenWidth-20, 95);
            butOk.frame = CGRectMake(10, CGRectGetMaxY(self.textView.frame)+100, ScreenWidth-20, 50);
        }
    }else {
        textField.font = FONT_(14.5);
        butOk.titleLabel.font = FONT_(14.5);
        if (A == 0) {
            textField.frame = CGRectMake(10, 20+NAVIGATION_BAR_HEIGHT, ScreenWidth-20, 58);
            butOk.frame = CGRectMake(10, CGRectGetMaxY(textField.frame)+100, ScreenWidth-20, 58);
        }else{
            self.textView.frame = CGRectMake(10, 20+NAVIGATION_BAR_HEIGHT, ScreenWidth-20, 98);
            butOk.frame = CGRectMake(10, CGRectGetMaxY(self.textView.frame)+100, ScreenWidth-20, 50);
        }
    }
}
#pragma mark - 确定按钮
-(void)clickButOk
{
    __weak typeof(self) weakSelf = self;
    UITextField * textField = [weakSelf.view viewWithTag:1];
    if ([self.whereFrom isEqualToString:@"1"]) {
        if (textField.text.length == 0) {
            [weakSelf initWithtring:@"请填写你要修改成的昵称!"];
            return;
        }
    }else if ([self.whereFrom isEqualToString:@"0"]){
        if (self.textView.text.length == 0) {
            [weakSelf initWithtring:@"请填写您的个人简历!"];
            return;
        }
    }
    else{
        if (self.textView.text.length == 0) {
            [weakSelf initWithtring:@"请填写你要修改的个人介绍!"];
            return;
        }
    }
    if ([self.whereFrom isEqualToString:@"1"]) {
        [LSZRequestData initWithModifyNickname:textField.text :^(BOOL isOK, NSString * Str, NSDictionary * diction) {
            if (isOK == YES) {
                [weakSelf initWithtring:@"修改昵称成功"];
                [weakSelf performSelector:@selector(clickReturn) withObject:nil afterDelay:1.5];
            }else{
                [weakSelf initWithtring:Str];
            }
        }];
    }else if ([self.whereFrom isEqualToString:@"0"]){
        UINavigationController *navigationVC = self.navigationController;
        NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
        for (UIViewController *vc in navigationVC.viewControllers) {
            [viewControllers addObject:vc];
            if ([vc isKindOfClass:[LSZQualificationCertificationVC class]]) {
                LSZQualificationCertificationVC *messageVC =(LSZQualificationCertificationVC *)vc;
                messageVC.IntroductionString = self.textView.text;
                [self.navigationController popToViewController:vc animated:YES];
                break;
            }
        }
    }
    else{
        [LSZRequestData ChangeGenderAndArea:@"interests" inputParameter:self.textView.text :^(BOOL isOK, NSString * Str, NSDictionary * dic) {
            if (isOK == YES) {
                [weakSelf initWithtring:Str];
                [weakSelf performSelector:@selector(clickReturn) withObject:nil afterDelay:1.5];
            }else{
                [weakSelf initWithtring:Str];
            }
        }];
    }
}
#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{

     if ([self.whereFrom isEqualToString:@"0"]) {
         if(textView.text.length < 1){
             textView.text = @"请填写你要修改的个人简介!";
             textView.textColor = [UIColor grayColor];
         }
     }else{
         if(textView.text.length < 1){
             textView.text = @"请填写你要修改的个人介绍!";
             textView.textColor = [UIColor grayColor];
         }
     }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{

    if ([self.whereFrom isEqualToString:@"0"]) {
        if([textView.text isEqualToString:@"请填写你要修改的个人简介!"]){
            textView.text=@"";
            textView.textColor=[UIColor blackColor];
        }
    }else{
        if([textView.text isEqualToString:@"请填写你要修改的个人介绍!"]){
            textView.text=@"";
            textView.textColor=[UIColor blackColor];
        }
    }
}
-(void)clickReturn
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
